home *** CD-ROM | disk | FTP | other *** search
- on UnionLists listOfListsOrMultipleLists
- if paramCount() > 1 then
- set listOfLists to []
- repeat with n = 1 to paramCount()
- append(listOfLists, param(n))
- end repeat
- else
- set listOfLists to param(1)
- end if
- if count(listOfLists) = 1 then
- return duplicate(getAt(listOfLists, 1))
- end if
- set newList to duplicate(getAt(listOfLists, 1))
- repeat with n = 2 to count(listOfLists)
- set listToAdd to getAt(listOfLists, n)
- repeat with listItem in listToAdd
- if not getPos(newList, listItem) then
- append(newList, listItem)
- end if
- end repeat
- end repeat
- return newList
- end
-
- on IntersectLists listOfListsOrMultipleLists
- if paramCount() > 1 then
- set listOfLists to []
- repeat with n = 1 to paramCount()
- append(listOfLists, param(n))
- end repeat
- else
- set listOfLists to param(1)
- end if
- if count(listOfLists) = 1 then
- return duplicate(getAt(listOfLists, 1))
- end if
- set newList to duplicate(getAt(listOfLists, 1))
- set listToCompare to getAt(listOfLists, 2)
- set listLength to count(newList)
- if not listLength then
- return []
- end if
- repeat with itemPosition = listLength down to 1
- if not getPos(listToCompare, getAt(newList, itemPosition)) then
- deleteAt(newList, itemPosition)
- end if
- end repeat
- if not count(newList) then
- return []
- end if
- if count(listOfLists) > 2 then
- set newListOfLists to duplicate(listOfLists)
- setAt(newListOfLists, 1, newList)
- deleteAt(newListOfLists, 2)
- return IntersectLists(newListOfLists)
- else
- return newList
- end if
- end
-
- on SubtractLists listsOrListOfLists
- if paramCount() > 1 then
- set listOfLists to []
- repeat with n = 1 to paramCount()
- append(listOfLists, param(n))
- end repeat
- else
- set listOfLists to param(1)
- end if
- if count(listOfLists) = 1 then
- return duplicate(getAt(listOfLists, 1))
- end if
- set newList to duplicate(getAt(listOfLists, 1))
- repeat with n = 2 to count(listOfLists)
- if count(newList) = 0 then
- return newList
- end if
- set listToSubtract to getAt(listOfLists, n)
- repeat with listItem in listToSubtract
- set position to getPos(newList, listItem)
- if position then
- deleteAt(newList, position)
- end if
- end repeat
- end repeat
- return newList
- end
-